package com.ruoyi.novel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.novel.domain.Search;
import com.ruoyi.novel.service.ISearchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 搜索记录Controller
 *
 * @author 张三
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/novel/search")
public class SearchController extends BaseController
{
    @Autowired
    private ISearchService searchService;

    /**
     * 查询搜索记录列表
     */
    @PreAuthorize("@ss.hasPermi('novel:search:list')")
    @GetMapping("/list")
    public TableDataInfo list(Search search)
    {
        startPage();
        List<Search> list = searchService.selectSearchList(search);
        return getDataTable(list);
    }

    /**
     * 导出搜索记录列表
     */
    @PreAuthorize("@ss.hasPermi('novel:search:export')")
    @Log(title = "搜索记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Search search)
    {
        List<Search> list = searchService.selectSearchList(search);
        ExcelUtil<Search> util = new ExcelUtil<Search>(Search.class);
        util.exportExcel(response, list, "搜索记录数据");
    }

    /**
     * 获取搜索记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('novel:search:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(searchService.selectSearchById(id));
    }

    /**
     * 新增搜索记录
     */
    @PreAuthorize("@ss.hasPermi('novel:search:add')")
    @Log(title = "搜索记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Search search)
    {
        return toAjax(searchService.insertSearch(search));
    }

    /**
     * 修改搜索记录
     */
    @PreAuthorize("@ss.hasPermi('novel:search:edit')")
    @Log(title = "搜索记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Search search)
    {
        return toAjax(searchService.updateSearch(search));
    }

    /**
     * 删除搜索记录
     */
    @PreAuthorize("@ss.hasPermi('novel:search:remove')")
    @Log(title = "搜索记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(searchService.deleteSearchByIds(ids));
    }
}
